class TestStack extends Test
{
    public constructor(sprite:DebugDraw)
    {
        super(sprite);
        this.createScene();
    }

    private createScene():void
    {
        let fd:Box2D.Dynamics.b2FixtureDef = new Box2D.Dynamics.b2FixtureDef();
        let sd:Box2D.Collision.Shapes.b2PolygonShape = new Box2D.Collision.Shapes.b2PolygonShape();
        let bd:Box2D.Dynamics.b2BodyDef = new Box2D.Dynamics.b2BodyDef();
        bd.type = Box2D.Dynamics.b2Body.b2_dynamicBody;
        bd.bullet = true;

        let b:Box2D.Dynamics.b2Body;
        fd.density = 1.0;
        fd.friction = 0.5;
        fd.restitution = 0.1;
        fd.shape = sd;
        let i:number;
        //create 3 stacks
        for(i = 0; i < 10; i++)
        {
            sd.SetAsBox((10)/this.m_physScale, (10)/ this.m_physScale);
            bd.position.Set((640 / 2 + 100) / this.m_physScale, (360-5-i*25) / this.m_physScale);
            b = this.m_world.CreateBody(bd);
            b.CreateFixture(fd);
        }
        for(i = 0; i < 10; i++)
        {
            sd.SetAsBox(10 / this.m_physScale, 10 / this.m_physScale);
            bd.position.Set((640 / 2 - 0 + Math.random() * 0.02 - 0.01) / this.m_physScale, (360 - 5 - i * 25) / this.m_physScale);
            b = this.m_world.CreateBody(bd);
            b.CreateFixture(fd);
        }
        for(i = 0; i < 10; i++)
        {
            sd.SetAsBox(10 / this.m_physScale, 10 / this.m_physScale);
            bd.position.Set((640 / 2 + 200 + Math.random() * 0.02 - 0.01)/ this.m_physScale, (360 - 5 - i* 25) / this.m_physScale);
            b = this.m_world.CreateBody(bd);
            b.CreateFixture(fd);
        }
        //create ramp;
        let vxs:Box2D.Common.Math.b2Vec2[] = [new Box2D.Common.Math.b2Vec2(0,0),
                                              new Box2D.Common.Math.b2Vec2(0, -100 / this.m_physScale),
                                              new Box2D.Common.Math.b2Vec2(200 / this.m_physScale, 0)];
        sd.SetAsArray(vxs, vxs.length);
        fd.density = 0;
        bd.type = Box2D.Dynamics.b2Body.b2_staticBody;
        bd.userData = "ramp";
        bd.position.Set(0, 360 / this.m_physScale);
        b = this.m_world.CreateBody(bd);
        b.CreateFixture(fd);

        //create ball;
        let cd:Box2D.Collision.Shapes.b2CircleShape = new Box2D.Collision.Shapes.b2CircleShape();
        cd.SetRadius(40 / this.m_physScale);
        fd.density = 2;
        fd.restitution = 0.2;
        fd.friction = 0.5;
        fd.shape = cd;
        bd.type = Box2D.Dynamics.b2Body.b2_dynamicBody;
        bd.userData = "ball";
        bd.position.Set(50 / this.m_physScale, 100 / this.m_physScale);
        b = this.m_world.CreateBody(bd);
        b.CreateFixture(fd);
    }
}